// ml:run = $bin < input
#include <iostream>
#include <fstream>
#include <vector>

int n, k;
std::vector<std::vector<int>> all;
int head[20];

std::ifstream fin{"easy.in"};
std::ofstream fout{"easy.out"};

int main()
{
    std::ios_base::sync_with_stdio(false);
    fin >> n >> k;
    all.resize(n);
    for (int i = 0; i < n; i++) {
        int p; fin >> p;
        all[i].resize(p);
        for (int j = 0; j < p; j++)
            fin >> all[i][j];
    }
    int now = 0, tot = 0, count = 0, full = 0;
    for (; count < k && full < n; now = (now + 1) % n) {
        if (head[now] < (int)all[now].size()) {
            if (all[now][head[now]] >= tot) {
                tot += all[now][head[now]];
                count++;
            }
            head[now]++;
            if (head[now] == (int)all[now].size()) full++;
        } else {
            if (50 >= tot) {
                tot += 50;
                count++;
            }
        }
    }
    if (count < k) tot += 50 * (k - count);
    fout << tot << "\n";
}

